//
//  UserMessageService.m
//  AILock
//
//  Created by 谭亚明 on 2020/6/23.
//  Copyright © 2020 tym. All rights reserved.
//

#import "UserMessageService.h"
#import "YYModel.h"
@implementation UserMessageService

/*获取用户消息列表*/
-(void)getFindUsermessagesFamilyID:(NSInteger)familyId
                              type:(NSInteger)type
                       pageIndex:(NSInteger)index
                       equipmentId:(NSString*)equipmentId
                  equipmentMsgType:(NSInteger)equipmentMsgType
                        completion:(void(^)(LMJBaseResponse *respon, NSArray<UserMessageModel*>*mesageArray))completion{
    
    NSDictionary *dic = @{@"page":@(index), @"familyId":@(familyId),
                          @"type":@(type),
                          @"equipmentId":equipmentId,
                          @"equipmentMsgType":equipmentMsgType? @(equipmentMsgType):@""
    };
    [self GET:urlUsermessagefindmessages parameters:dic completion:^(LMJBaseResponse *response) {
        completion(response,[NSArray yy_modelArrayWithClass:[UserMessageModel class] json: response.responseObject[@"data"][@"content"]]);
    }];
}

/*获取用户各类型消息*/
-(void)getFindUsermessagesFamilyID:(NSInteger)familyId completion:(void(^)(LMJBaseResponse *respon, NSArray<UserMessageModel*>*mesageArray))completion{
    
    NSDictionary *dic = @{@"familyId":@(familyId)
    };
    [self GET:urlUsermessagefindtypemessage parameters:dic completion:^(LMJBaseResponse *response) {
        completion(response,[NSArray yy_modelArrayWithClass:[UserMessageModel class] json: response.responseObject[@"data"]]);
    }];
}

/*读取消息*/
-(void)getReadmessage:(NSString*)messageIDs completion:(void(^)(LMJBaseResponse *respon))completion{
    
    NSDictionary *dic = @{@"ids":messageIDs
    };
    [self POST:urlReadmessage parameters:dic completion:^(LMJBaseResponse *response) {
        completion(response);
    }];
}

/*获取用户未读消息数量*/
-(void)getUnreadnumFamilyId:(NSInteger)familyId completion:(void(^)(LMJBaseResponse *respon))completion{
    
    NSDictionary *dic = @{@"familyId":@(familyId)
    };
    [self GET:urlUsermessageunreadnum parameters:dic completion:^(LMJBaseResponse *response) {
        completion(response);
    }];

}

/** 设置用户设备消息通知*/
-(void)getEquipmentmessageconfigId:(NSInteger)messageID
                              type:(NSInteger)type
                          familyId:(NSInteger)familyId
                            isOpen:(BOOL)isOpen
                       equipmentId:(NSInteger)equipmentId
                        completion:(void(^)(LMJBaseResponse *respon))completion{
    NSMutableDictionary *dic = [[NSMutableDictionary alloc] initWithDictionary: @{@"id":messageID?@(messageID):@"",
                                           @"type":@(type),
                                           @"familyId":@(familyId),
                                           @"equipmentId":@(equipmentId),
                                           @"isopen":@(isOpen)
    }];
    [self POST:urlSetequipmentmessageconfig parameters:dic completion:^(LMJBaseResponse *response) {
        completion(response);
    }];
}

/** 设置用户设备消息通知*/
-(void)getUserMessageconfigId:(NSInteger)messageID
                              startTime:(NSString*)startTime
                           endTime:(NSString*)endTime
                          familyId:(NSInteger)familyId
                            isOpen:(BOOL)isOpen
                        completion:(void(^)(LMJBaseResponse *respon))completion{
    
    NSMutableDictionary *dic = [[NSMutableDictionary alloc] initWithDictionary: @{@"id":@(messageID),
                                                                                  @"endTime":endTime?endTime:@"",
                                           @"familyId":@(familyId),
                                                                                  @"startTime":startTime?startTime:@"",
                                           @"isopen":@(isOpen)
    }];
    
    if(!messageID){
        [dic removeObjectForKey:@"id"];
    }
    [self POST:urlSetUsermessageconfig parameters:dic completion:^(LMJBaseResponse *response) {
        completion(response);
    }];
}

/*查询家庭用户设备消息免打扰*/
-(void)getFindusermessageconfig:(NSInteger)familyId completion:(void(^)(LMJBaseResponse *respon,MessageConfig *config))completion{
    NSDictionary *dic = @{@"familyId":@(familyId)
    };
    [self GET:urlFindusermessageconfig parameters:dic completion:^(LMJBaseResponse *response) {
        completion(response,[MessageConfig yy_modelWithJSON:response.responseObject[@"data"]]);
    }];
}

@end
